home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_vim.idb / usr / freeware / share / vim / syntax / sh.vim.z / sh.vim
Encoding:
Text File  |  1998-10-28  |  8.4 KB  |  188 lines

  1. " Vim syntax file
  2. " Language:    shell (sh) Korn shell (ksh) bash (sh)
  3. " Maintainer:    Lennart Schultz <Lennart.Schultz@ecmwf.int>
  4. " Last change:    1997 November 24
  5. "
  6. " Using the following VIM variables:
  7. " is_kornshell               if defined enhance with kornshell syntax
  8. " is_bash                    if defined enhance with bash syntax
  9. "
  10. " This is a complete redesign including many ideas from
  11. " ╔ric Brunet (eric.brunet@ens.fr)
  12. "
  13. " Updated 1997 November 21
  14. "    With many good inputs from ╔ric Brunet, especially he got the
  15. "    case statement to work!
  16. " Updated 1997 November 24
  17. "     Sync included with thanks to Dr. Charles E. Campbell Jr <cec@gryphon.gsfc.nasa.gov>
  18. "    Echo included with thanks to ╔ric Brunet
  19. "    [ \t] removed using \s instead
  20.  
  21. " Remove any old syntax stuff hanging around
  22. syn clear
  23. " sh syntax is case sensitive
  24. syn case match
  25.  
  26. syn keyword    shTodo        contained TODO
  27. syn match    shComment        "#.*$" contains=shTodo
  28.  
  29. " String and Character constants
  30. "===============================
  31. syn match   shNumber       "-\=\<[0-9]\+\>"
  32. syn match   shSpecial      contained "\\[0-9][0-9][0-9]\|\\[abcfnrtv]"
  33. syn region  shSinglequote matchgroup=shOperator start=+'+ end=+'+
  34. syn region  shDoubleQuote      matchgroup=shOperator start=+"+ skip=+\\"+ end=+"+ contains=shDeref,shCommandSub,shSpecialShellVar,shSpecial
  35. syn match  shSpecial  "\\[\\\"\'`$]"
  36.     " This must be after the strings, so that bla \" be correct
  37. syn region shEmbeddedEcho contained matchgroup=shStatement start="\<echo\>" skip="\\$" matchgroup=shOperator end="$" matchgroup=NONE end="[<>;&|`]"me=e-1 end="[0-9][<>]"me=e-2 end="#"me=e-1 contains=shNumber,shSinglequote,shDeref,shSpecialVar,shSpecial,shOperator,shDoubleQuote
  38.      " This one is needed INSIDE a CommandSub, so that
  39.      " `echo bla` be correct
  40. syn region shEcho matchgroup=shStatement start="\<echo\>" skip="\\$" matchgroup=shOperator end="$" matchgroup=NONE end="[<>;&|]"me=e-1 end="[0-9][<>]"me=e-2 end="#"me=e-1 contains=shNumber,shCommandSub,shSinglequote,shDeref,shSpecialVar,shSpecial,shOperator,shDoubleQuote
  41.  
  42. " Tests
  43. "======
  44. if exists("is_kornshell")
  45. syn region  shNone transparent matchgroup=shOperator start="\[\[" skip=+\\\\\|\\$+ end="\]\]" contains=ALLBUT,shFunction,shTestError,shIdentifier,shCase,shDTestError
  46. endif
  47. syn region  shNone transparent matchgroup=shOperator start="\[" skip=+\\\\\|\\$+ end="\]" contains=ALLBUT,shFunction,shTestError,shIdentifier,shCase,shDTestError
  48. syn region  shNone transparent matchgroup=shStatement start="\<test\>" skip=+\\\\\|\\$+ matchgroup=NONE end="[;&|]"me=e-1 end="$" contains=ALLBUT,shFunction,shIdentifier,shCase
  49. syn match   shTestOpr contained "[!=]\|-.\>\|-\(nt\|ot\|ef\|eq\|ne\|lt\|le\|gt\|ge\)\>"
  50.  
  51. syn region  shDo transparent matchgroup=shStatement start="\<do\>" end="\<done\>" contains=ALLBUT,shFunction,shDoError,shCase
  52. syn region  shIf transparent matchgroup=shStatement start="\<if\>" end="\<fi\>" contains=ALLBUT,shFunction,shIfError,shCase
  53. syn region  shFor  matchgroup=shStatement start="\<for\>" end="\<in\>" contains=ALLBUT,shFunction,shInError,shCase
  54. syn region shCaseEsac transparent matchgroup=shStatement start="\<case\>" matchgroup=NONE end="\<in\>"me=s-1 contains=ALLBUT,shFunction,shCaseError nextgroup=shCaseEsac
  55. syn region shCaseEsac matchgroup=shStatement start="\<in\>" end="\<esac\>" contains=ALLBUT,shFunction,shCaseError
  56. syn region shCase matchgroup=shStatement contained start="\s*.\+)"  end=";;" contains=ALLBUT,shFunction,shCaseError,shCase
  57. syn region  shNone transparent matchgroup=shOperator start="{" end="}" contains=ALLBUT,shCurlyError,shCase
  58. syn region  shSubSh transparent matchgroup=shOperator start="(" end=")" contains=ALLBUT,shParenError,shCase
  59.  
  60. " Misc
  61. "=====
  62. syn match   shOperator        "[!&;|=]"
  63. syn match   shWrapLineOperator    "\\$"
  64. syn region  shCommandSub   start="`" skip="\\`" end="`" contains=ALLBUT,shFunction,shCommandSub,shTestOpr,shCase,shEcho
  65.  
  66. syn match   shSource    "^\.\s"
  67. syn match   shSource    "\s\.\s"
  68. syn region  shColon    start="^\s*:" end="$\|" end="#"me=e-1 contains=ALLBUT,shFunction,shTestOpr,shCase
  69.  
  70. " File redirection highlighted as operators
  71. "==========================================
  72. syn match    shRedir    "[0-9]\=>\(&[-0-9]\)\="
  73. syn match    shRedir    "[0-9]\=>>-\="
  74. syn match    shRedir    "[0-9]\=<\(&[-0-9]\)\="
  75. syn match    shRedir    "[0-9]<<-\="
  76. " Future:
  77. "syn region      shRedir start="<<\([!     ;&|]\+" end="\1"
  78.  
  79. " Identifiers
  80. "============
  81. syn match  shIdentifier "\<[a-zA-Z_][a-zA-Z0-9_]*\>="me=e-1
  82. if exists("is_bash")
  83. syn region shIdentifier matchgroup=shStatement start="\<\(declare\|typeset\|local\|export\|set\|unset\)\>[^/]"me=e-1 matchgroup=shOperator skip="\\$" end="$\|[;&]" matchgroup=NONE end="#\|="me=e-1 contains=shTestError,shCurlyError,shWrapLineOperator
  84. elseif exists("is_kornshell")
  85. syn region shIdentifier matchgroup=shStatement start="\<\(typeset\|set\|export\|unset\)\>[^/]"me=e-1 matchgroup=shOperator skip="\\$" end="$\|[;&]" matchgroup=NONE end="#\|="me=e-1 contains=shTestError,shCurlyError,shWrapLineOperator
  86. else
  87. syn region shIdentifier matchgroup=shStatement start="\<\(set\|export\|unset\)\>[^/]"me=e-1 matchgroup=shOperator skip="\\$" end="$\|[;&]" matchgroup=NONE end="#\|="me=e-1 contains=shTestError,shCurlyError,shWrapLineOperator
  88. endif
  89.         " The [^/] in the start pattern is a kludge to avoid bad
  90.         " highlighting with cd /usr/local/lib...
  91.  
  92. syn region  shFunction transparent matchgroup=shFunctionName     start="^\s*\<[a-zA-Z_][a-zA-Z0-9_]*\>\s*()\s*{" end="}" contains=ALLBUT,shFunction,shCurlyError,shCase
  93. syn region shDeref         start="\${" end="}"
  94. syn match  shDeref         "\$\<[a-zA-Z_][a-zA-Z0-9_]*\>"
  95. syn match  shSpecialShellVar "\$[-#@*$?!0-9]"
  96.  
  97. "Error Codes
  98. syn match   shDoError "\<done\>"
  99. syn match   shIfError "\<fi\>"
  100. syn match   shInError "\<in\>"
  101. syn match     shCaseError ";;"
  102. syn match   shEsacError "\<esac\>"
  103. syn match     shCurlyError "}"
  104. syn match     shParenError ")"
  105. if exists("is_kornshell")
  106. syn match     shDTestError "]]"
  107. endif
  108. syn match     shTestError "]"
  109.  
  110. " A bunch of useful sh keywords
  111. syn keyword shStatement    break cd chdir continue eval exec
  112. syn keyword shStatement    exit kill newgrp pwd read readonly
  113. syn keyword shStatement    return shift test trap
  114. syn keyword shStatement    ulimit umask wait
  115. syn keyword shConditional  else then elif while
  116.  
  117. if exists("is_kornshell") || exists("is_bash")
  118. syn keyword shStatement    bg fg jobs stop suspend
  119. syn keyword shFunction     function
  120. syn keyword shStatement    alias fc getopts hash history let print time
  121. syn keyword shStatement    times type whence unalias
  122. syn keyword shRepeat       select until
  123. if exists("is_bash")
  124. syn keyword shStatement    source bind builtin dirs
  125. syn keyword shStatement    disown enable help history
  126. syn keyword shStatement    logout popd pushd shopt
  127. else
  128. syn keyword shStatement    login newgrp
  129. endif
  130. endif
  131.  
  132. " Syncs
  133. " =====
  134. syn sync minlines=50
  135. syn sync match shDoSync       grouphere  shDo       "\<do\>"
  136. syn sync match shDoSync       groupthere shDo       "\<done\>"
  137. syn sync match shIfSync       grouphere  shIf       "\<if\>"
  138. syn sync match shIfSync       groupthere shIf       "\<fi\>"
  139. syn sync match shForSync      grouphere  shFor      "\<for\>"
  140. syn sync match shForSync      groupthere shFor      "\<in\>"
  141. syn sync match shCaseEsacSync grouphere  shCaseEsac "\<case\>"
  142. syn sync match shCaseEsacSync groupthere shCaseEsac "\<esac\>"
  143.  
  144. if !exists("did_sh_syntax_inits")
  145.   let did_sh_syntax_inits = 1
  146. " The default methods for highlighting.  Can be overridden later
  147.   hi link shSinglequote        shString
  148.   hi link shDoubleQuote        shString
  149.   hi link shSource        shOperator
  150.   hi link shWrapLineOperator    shOperator
  151.   hi link shColon        shStatement
  152.   hi link shRedir        shOperator
  153.   hi link shSpecialShellVar    shShellVariables
  154.   hi link shDeref        shShellVariables
  155.   hi link shTestOpr        shConditional
  156.   hi link shEcho        shString
  157.   hi link shEmbeddedEcho    shString
  158.   hi link shInError        Error
  159.   hi link shCaseError        Error
  160.   hi link shEsacError        Error
  161.   hi link shDoError        Error
  162.   hi link shIfError        Error
  163.   hi link shCurlyError        Error
  164.   hi link shParenError        Error
  165.   hi link shTestError        Error
  166. if exists("is_kornshell")
  167.   hi link shDTestError        Error
  168. endif
  169.   hi link shCommandSub        Special
  170.   hi link shFunctionName    Function
  171.   hi link shStatement        Statement
  172.   hi link shConditional        Conditional
  173.   hi link shNumber        Number
  174.   hi link shString        String
  175.   hi link shComment        Comment
  176.   hi link shSpecial        Special
  177.   hi link shTodo        Todo
  178.   hi link shIdentifier        Identifier
  179.   hi link shShellVariables    PreProc
  180.   hi link shOperator        Operator
  181.   hi link shFunction            Function
  182.   hi link shRepeat        Repeat
  183. endif
  184.  
  185. let b:current_syntax = "sh"
  186.  
  187. " vim: ts=8
  188.